#include "qbullet.h"
#include<QPainter>
#include<QGraphicsItem>
#include<QPixmap>
#include<QString>
#include<QRect>
#include<QGraphicsScene>

QBullet::QBullet(const QString & fileName,QGraphicsScene *scence,qreal angle):QpixmapItem(fileName,scence)
{

    this->scence=scence;
    qreal dx,dy;

    qreal rad;
    rad=angle*3.14/180;
    dx=140*cos(rad);
    dy=140*sin(rad);
    this->setPos(scence->width()/2+dx,scence->height()-dy);
    this->setRotation(90-angle);
}

void QBullet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->drawPixmap(-pixmap.width(),-pixmap.height(),pixmap);
    if(this->collidingItems().count()>0)
    {
        docolliding();
    }
}

void QBullet::advance(int phase)
{
    if(mapToScene(0,0).x()<=0||mapToScene(0,0).x()>=1500||mapToScene(0,0).y()<=0)
    {
        delete this;
    }
    else
    {
        this->setPos(mapToScene(0,-20));
    }
}

void QBullet::docolliding()
{

    QNet *net=new QNet("img/BO.png",this->scence);
    net->setPos(mapToScene(0,0));

    delete this;
}
